package com.hhf.springboot.model.vo;

import cn.hutool.json.JSONUtil;
import com.hhf.springboot.model.entity.BisheProject;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 毕设项目视图
 *
 * @author hhf
 * @from <a href="https://gitee.com/hanhuaifei/projects">我的gitee</a>
 * @Date 2024/9/26
 */
@Data
public class BisheProjectVO implements Serializable {

    /**
     * id
     */
    private Long id;

    /**
     * 标题
     */
    private String title;

    /**
     * 子标题
     */
    private String subtitle;


    /**
     * 功能演示URL
     */
    private String demoVideoUrl;

    /**
     * 介绍文档
     */
    private String introduce;

    /**
     * 代码价格（单位：分）
     */
    private Integer codePrice;

    /**
     * 论文价格（单位：分）
     */
    private Integer docPrice;

    /**
     * 毕设项目展示图片
     */
    private String cover;

    /**
     * 访问数
     */
    private Long clickNum;

    /**
     * 状态(0-关闭,1-开启)
     */
    private Integer status;

    /**
     * 创建用户 id
     */
    private Long userId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;


    private static final long serialVersionUID = 1L;

    /**
     * 标签列表
     */
    private List<String> tagList;

    /**
     * 创建用户信息
     */
    private UserVO user;

    /**
     * 封装类转对象
     *
     * @param bisheProjectVO
     * @return
     */
    public static BisheProject voToObj(BisheProjectVO bisheProjectVO) {
        if (bisheProjectVO == null) {
            return null;
        }
        BisheProject bisheProject = new BisheProject();
        BeanUtils.copyProperties(bisheProjectVO, bisheProject);
        List<String> tagList = bisheProjectVO.getTagList();
        bisheProject.setTags(JSONUtil.toJsonStr(tagList));
        return bisheProject;
    }

    /**
     * 对象转封装类
     *
     * @param bisheProject
     * @return
     */
    public static BisheProjectVO objToVo(BisheProject bisheProject) {
        if (bisheProject == null) {
            return null;
        }
        BisheProjectVO bisheProjectVO = new BisheProjectVO();
        BeanUtils.copyProperties(bisheProject, bisheProjectVO);
        bisheProjectVO.setTagList(JSONUtil.toList(bisheProject.getTags(), String.class));
        return bisheProjectVO;
    }
}
